package com.lry.pda.bottom.c.backend.executor;

import com.lry.pda.bottom.c.backend.code.CodeKey;
import com.lry.pda.bottom.c.backend.code.CodeNode;
import com.lry.pda.bottom.c.frontend.CTokenType;

public class ExecutorFactory {

    public static Executor getExecutor(CodeNode node) {
        CTokenType type = (CTokenType)node.getAttr(CodeKey.TokenType);
        switch (type) {
            case UNARY:
                return new UnaryExecutor();
            case BINARY:
                return new BinaryExecutor();
            case NO_COMMA_EXPR:
                return new NoCommaExprExecutor();
            case EXPR:
                return new ExprExecutor();
            case STATEMENT:
                return new StatementExecutor();
            case STMT_LIST:
                return new StatementListExecutor();
            case TEST:
                return new TestExecutor();
            case IF_STATEMENT:
                return new IfStatementExecutor();
            case IF_ELSE_STATEMENT:
                return new ElseStatementExecutor();
            case DECL:
                return new DeclExecutor();
            case DECL_LIST:
                return new DecLListExecutor();
            case OPT_EXPR:
                return new OptExprExecutor();
            case END_OPT_EXPR:
                return new EndOptExecutor();
            case FUNCT_DECL:
                return new FuncDeclExecutor();
            case EXT_DEF:
                return new ExtDefExecutor();
            case ARGS:
                return new ArgExecutor();
        }
//        System.err.println("Not suitable Executor found, node is: " + node.toString());
        return null;
    }

}
